﻿using Mozi.HttpEmbedded;
using Mozi.Live;
using System;

namespace Mozi.RTSP.Test
{
    class Program
    {

        static void Main(string[] args)
        {
            RTSPServer rtsp = new RTSPServer();

            rtsp.RequestHandled = (host,port,ctx) =>
            {
                #region 这里使用的是自研的日志记录器，开发者在使用测试用例时请注释掉此段
                string urlLogAddress = "http://127.0.0.1:2343/log";

                Console.WriteLine($"{ctx.Request.RequestLineString}=>{ctx.Response.StatusLineString}");

                HttpClient hc = new HttpClient();
                hc.SetAuthorization(new HttpEmbedded.Auth.BasicAuth());
                hc.SetUser("admin", "admin");
                hc.Post(urlLogAddress, $"# [{DateTime.Now:u}] <<{ctx.ClientAddress}:{ctx.ClientPort}");
                hc.Post(urlLogAddress, System.Text.Encoding.UTF8.GetString(ctx.Request.GetBuffer()));

                hc.Post(urlLogAddress, $"# [{DateTime.Now:u}] >>{ctx.ClientAddress}:{ctx.ClientPort}");
                hc.Post(urlLogAddress, System.Text.Encoding.UTF8.GetString(ctx.Response.GetBuffer()));

                #endregion
            };
            rtsp.Start();
            rtsp.StartRTP(3005);
            rtsp.StartRTCP(3006);

            HttpServer hs = new HttpServer();
            hs.UseStaticFiles("");
            hs.Start(9090);
            Console.ReadLine();
        }
    }
}
